<?php
require_once("include.php");
require_once("periodstateobj.php");
session_start();
include("menu.php");
//authorise("userinput");
(isset($_REQUEST["restart"])) ? $restart = $_REQUEST["restart"] : $restart = "NULL" ;
(isset($_REQUEST["res"])) ? $res = $_REQUEST["res"] : $res = "NULL" ;
(isset($_REQUEST["sub"])) ? $sub = $_REQUEST["sub"] : $sub = "NULL" ;
(isset($_REQUEST["f1"])) ? $periodid = $_REQUEST["f1"] : $periodid = "NULL" ;
(isset($_REQUEST["f6"])) ? $subledgerid = $_REQUEST["f6"] : $subledgerid = "NULL";
//unset($_SESSION["periodstate"]);
if (!(isset($_SESSION["periodstate"]))) {$obj = new periodstate();}
$obj=&$_SESSION["periodstate"] ;
if ($obj->header[2] !== "") {
 // have already read or created an item
 $obj->applyfromrequest();
 if ($sub == "Save" && $obj->valid) {
  $obj->writedb();
  $obj->confirmfiled();
 } elseif($res=="restart") {
  unset($_SESSION["periodstate"]);
 } else {
  $obj->showform();
 }
} elseif ($periodid == "NULL") {
 // First call
 $obj->showchoose();
} elseif ($sub == "Continue") {
 if($obj->readdb()) {
  $obj->showform();
 } else {
  $obj->showchoose();
 }
} else {
 $obj->showchoose();
}
?>